package com.space.service.impl;

import com.space.dao.AdminDao;
import com.space.entity.Admin;
import com.space.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : 港某
 * @date : 2020/2/12 11:13
 */
@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    AdminDao adminDao;

    @Override
    public List<Admin> selectAllAdmin() {
        return adminDao.selectAllAdmin();
    }

    @Override
    public Admin selectAdminByAccount(String adminAccount) {
        return adminDao.selectAdminByAccount(adminAccount);
    }

    @Override
    public Admin adminLogin(Admin admin) {
        if (admin.getAdminAccount() != null) {
            Admin newAdmin = adminDao.selectAdminByAccount(admin.getAdminAccount());
            if (newAdmin != null) {
                if (newAdmin.getAdminPwd().equals(admin.getAdminPwd())) {
                    return newAdmin;
                }
            }
        }
        return null;
    }

    @Override
    public boolean checkAdminPwd(String adminAccount, String adminPwd) {
        Admin admin = adminDao.selectAdminByAccount(adminAccount);
        if (admin != null) {
            if (admin.getAdminPwd().equals(adminPwd)) {
                return true;
            }
        }
        return false;
    }
}
